package com.hflyeer.config;

import com.hflyeer.exception.StudentException;
import com.hflyeer.pojo.ResponseBean;
import com.hflyeer.util.ResponseUtil;
import org.springframework.web.bind.annotation.ControllerAdvice;
import org.springframework.web.bind.annotation.ExceptionHandler;
import org.springframework.web.bind.annotation.ResponseBody;

/**
 * GlobalExceptionHandler
 *
 * @author hflyeer
 * @date 2021-06-01
 * @describe
 */
@ControllerAdvice
public class GlobalExceptionHandler extends RuntimeException {


    @ExceptionHandler(StudentException.class)
    @ResponseBody
    public ResponseBean studentException(StudentException e){
        return ResponseUtil.fail(500,false,e.getMessage());
    }


    @ExceptionHandler(Exception.class)
    @ResponseBody
    public ResponseBean exception(Exception e){
        return ResponseUtil.fail(500,false,"内部错误");
    }
}
